var koa = require('koa');
var app = new koa();
var createLogger = require('concurrency-logger').default;
const session = require('koa-session');
const koaBody = require('koa-body');
const logger = createLogger({});
const routes = require('./controller/init')
const sessionConfig = require('./config/session')
const {sequelize, Sequelize} = require('./models')

sequelize.doConnect()

app.keys = ['some_secret_hurr'];

const port = 2003

app
  .use(logger)
  .use(koaBody())
  .use(session(sessionConfig, app))
  .use((ctx, next)=>{
    ctx._before = 1
    next()
  })


routes.forEach((item)=>{
  app.use(item.routes())
  app.use(item.allowedMethods({throw: true}))
})

app.listen(port);

console.log(`server listen ${port}`);
